package com.black.security.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

/**
 * @Author: Young
 * @CreateTime: 2025-08-13
 * @Description: security配置类
 * @Version: 1.0
 */
@Configuration
public class WebSecurityConfig {

    /**
     * 定义 BCrypt 加密器
     * @return
     */
    @Bean
    public PasswordEncoder passwordEncoder() {
        return new BCryptPasswordEncoder();
    }

    /**
     * 基于内存的用户信息加载
     * @return
     */
//    @Bean
//    public UserDetailsService userDetailsService() {
//        InMemoryUserDetailsManager inMemoryUserDetailsManager = new InMemoryUserDetailsManager();
//        inMemoryUserDetailsManager.createUser(User.withUsername("admin").password("{bcrypt}$2a$10$2fzj68kGu5NWzvc/oMmGs.Btqdaktx4mQ/4R69gXNuU73CbrgKpp6").roles("admin").build());
//        return inMemoryUserDetailsManager;
//    }

    /**
     * 基于数据库的用户信息管理
     * @return
     */
    @Bean
    public UserDetailsService userDetailsService() {
        DBUserDetailsManager dbUserDetailsManager = new DBUserDetailsManager();
        return dbUserDetailsManager;
    }

}
